package com.huike.game.Activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.huike.game.R;

import java.util.ArrayList;

import androidx.appcompat.app.AppCompatActivity;

public class GameActivity66 extends AppCompatActivity {

    private ImageView iv_left_image;
    private TextView tv_left_text;
    private TextView tv_content_title;
    private ImageView iv_rigth_image;
    private TextView tv_right_text;
    private GridView gv_game66_sub;
    private GridView gv_game66_add;
    private ArrayList<String> sub;
    private ArrayList<String> add;
    private   GVAdapterTop top;
    private   GVAdapterBut but;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game66);
        initView();

        sub = new ArrayList<>();
        add = new ArrayList<>();

        add.add("推荐");
        add.add("安全驾驶");

        sub.add("交通分类");
        sub.add("科技类");
        sub.add("路况类");
        sub.add("汽车类");
        sub.add("二手车类");
        sub.add("改装车");
        sub.add("违章");


        top = new GVAdapterTop();
        gv_game66_sub.setAdapter(top);

        but= new GVAdapterBut();
        gv_game66_add.setAdapter(but);


    }

    private void initView() {
        iv_left_image = (ImageView) findViewById(R.id.iv_left_image);
        tv_left_text = (TextView) findViewById(R.id.tv_left_text);
        tv_content_title = (TextView) findViewById(R.id.tv_content_title);
        iv_rigth_image = (ImageView) findViewById(R.id.iv_rigth_image);
        tv_right_text = (TextView) findViewById(R.id.tv_right_text);

        iv_rigth_image.setVisibility(View.GONE);
        tv_right_text.setVisibility(View.GONE);

        tv_content_title.setText("添加订阅");

        iv_left_image.setImageResource(R.drawable.tiao);

        tv_left_text.setVisibility(View.GONE);


        gv_game66_sub = (GridView) findViewById(R.id.gv_game66_sub);
        gv_game66_add = (GridView) findViewById(R.id.gv_game66_add);
    }

    class GVAdapterTop extends BaseAdapter {

        @Override
        public int getCount() {
            return sub.size();
        }

        @Override
        public Object getItem(int i) {
            return sub.get(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int i, View view, ViewGroup viewGroup) {

            ViewHolder holder = null;

            if (view == null) {
                view = View.inflate(GameActivity66.this, R.layout.game66_gv_sub, null);
                holder = new ViewHolder(view);

                view.setTag(holder);

            } else {
                holder = (ViewHolder) view.getTag();
            }

            holder.tv_Game66_sub.setText(sub.get(i));


            holder.iv_game66_sub.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    add.add(0,sub.get(i));
                    sub.remove(i);


                    but.notifyDataSetChanged();
                    top.notifyDataSetChanged();

                }
            });


            return view;
        }

    }


    class GVAdapterBut extends BaseAdapter {

        @Override
        public int getCount() {
            return add.size();
        }

        @Override
        public Object getItem(int i) {
            return add.get(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int i, View view, ViewGroup viewGroup) {

            ViewHolder holder = null;

            if (view == null) {
                view = View.inflate(GameActivity66.this, R.layout.game66_gv_add, null);
                 holder = new ViewHolder(view);
                 view.setTag(holder);

            } else {
                holder = (ViewHolder) view.getTag();
            }

            holder.tv_Game66_add.setText(add.get(i));


            holder.iv_gam66_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {


                    sub.add(0,add.get(i));
                    add.remove(i);
                    top.notifyDataSetChanged();
                    but.notifyDataSetChanged();

                }
            });


            return view;
        }

    }


    class ViewHolder {
        public View rootView;
        public ImageView iv_game66_sub;
        public TextView tv_Game66_sub;
        public TextView tv_Game66_add;
        public ImageView iv_gam66_add;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.iv_game66_sub = (ImageView) rootView.findViewById(R.id.iv_game66_sub);
            this.tv_Game66_sub = (TextView) rootView.findViewById(R.id.tv_Game66_sub);
            this.tv_Game66_add = (TextView) rootView.findViewById(R.id.tv_Game66_add);
            this.iv_gam66_add = (ImageView) rootView.findViewById(R.id.iv_gam66_add);
        }

    }

}
